import request from '@/utils/request'
import qs from 'qs'

export function findListByPage(params) {
  return request({
    url: '/api/script/convert/task' + '?' + qs.stringify(params, { indices: false }),
    method: 'get'
  })
}

export function queryById(pkId) {
  return request({
    url: '/api/script/convert/task/' + pkId,
    method: 'get'
  })
}

export function filesUpload(data) {
  return request({
    url: '/api/script/convert/list/improt',
    method: 'post',
    data
  })
}

export function download(pkId) {
  return request({
    url: '/api/script/convert/task/download/file/' + pkId,
    method: 'get',
    responseType: 'blob'
  })
}
export function scriptConvert(pkId) {
  return request({
    url: '/api/script/convert/task/convert/' + pkId,
    method: 'put'
  })
}

export function getScriptConvertType() {
  return request({
    url: '/api/script/convert/task/convert/type',
    method: 'get'
  })
}

export function getMigrationTypeInfos() {
  return request({
    url: '/api/script/convert/task/getMigrationTypeInfos',
    method: 'get'
  })
}

export function scriptVerify(pkId) {
  return request({
    url: '/api/script/convert/task/verify/' + pkId,
    method: 'put'
  })
}

export function del(pkIds) {
  return request({
    url: '/api/script/convert/task',
    method: 'delete',
    data: pkIds
  })
}

export function testData(pkid) {
  return request({
    url: '/api/script/convert/task/script',
    method: 'get',
    data: pkid
  })
}
export function add(data) {
  return request({
    url: '/api/script/convert/task',
    data: data,
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data;boundary=' + new Date().getTime()
    }
  })
}

export function upload(data) {
  return request({
    url: '/api/script/convert/task/upload',
    data: data,
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data;boundary=' + new Date().getTime()
    }
  })
}

export function downloadFile(taskPkId) {
  return request({
    url: '/api/script/convert/task/download/sourcefile/' + taskPkId,
    method: 'get',
    responseType: 'blob'
  })
}

export function convertFile(taskPkId) {
  return request({
    url: '/api/script/convert/task/download/convertfile/' + taskPkId,
    method: 'get',
    responseType: 'blob'
  })
}

export function proceduresConvert(data) {
  return request({
    url: '/api/script/convert/task/datasource',
    method: 'post',
    data
  })
}

export function checkTaskNameExists(taskName) {
  return request({
    url: '/api/script/convert/task/checkTaskName',
    method: 'post',
    data: taskName
  })
}

export default {
  proceduresConvert,
  queryById,
  testData,
  convertFile,
  findListByPage,
  add,
  scriptConvert,
  getScriptConvertType,
  getMigrationTypeInfos,
  scriptVerify,
  del,
  download,
  downloadFile,
  filesUpload,
  checkTaskNameExists,
  upload
}
